feat(nitro): Handle sourcemap preparation and upload#19304
feat(nitro): Handle sourcemap preparation and upload#19304logaretm wants to merge 16 commits intoawad/create-nitro-sdk-metadatafrom
Conversation
Codecov Results 📊Generated by Codecov Action |
size-limit report 📦
|
1923dda to
be2f037
Compare
0d86a79 to
9f6254a
Compare
be2f037 to
3b30e36
Compare
9f6254a to
63a2175
Compare
3b30e36 to
36c96b6
Compare
d3e3ae1 to
a24cad5
Compare
|
This pull request has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you apply the label |
3cf1515 to
342ea3b
Compare
a24cad5 to
1583866
Compare
342ea3b to
8d44437
Compare
a967e7a to
00bd835
Compare
There was a problem hiding this comment.
Pull request overview
Adds build-time sourcemap generation + post-build sourcemap (and debug ID) handling to the @sentry/nitro SDK by wiring Nitro’s compiled hook to @sentry/bundler-plugin-core.
Changes:
- Introduces
packages/nitro/src/sourceMaps.tsto configure Nitro sourcemap settings and to run a post-build upload flow viacreateSentryBuildPluginManager. - Threads
SentryNitroOptionsthrough module setup so sourcemap behavior can be configured fromwithSentryConfig/setupSentryNitroModule. - Adds Vitest coverage for option-shaping and basic hook registration behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/nitro/src/sourceMaps.ts | New sourcemap config + post-build hook which injects debug IDs and uploads sourcemaps via bundler-plugin-core |
| packages/nitro/test/sourceMaps.test.ts | New unit tests for plugin option building, config mutation, and hook registration |
| packages/nitro/src/module.ts | Passes Sentry options into module setup to enable sourcemap handling |
| packages/nitro/src/config.ts | Defines SentryNitroOptions from bundler-plugin-core options and enables sourcemap config during module setup |
| packages/nitro/rollup.npm.config.mjs | Marks @sentry/bundler-plugin-core as external in the package build |
| packages/nitro/package.json | Adds @sentry/bundler-plugin-core dependency |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Implements HTTP server instrumentation for both `h3` and `srvx` by listening to their tracing channel events. - `h3` TC PR: h3js/h3#1251 - `srvx` TC PR: h3js/srvx#141 Closes #18123 --- **This PR is part of a stack:** - #20358 - #19224 - #19225 👈 - #19304 --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4cd6415 to
47d85ab
Compare
d3328c8 to
25e2ec0
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 3 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 25e2ec0. Configure here.
Implements HTTP server instrumentation for both `h3` and `srvx` by listening to their tracing channel events. - `h3` TC PR: h3js/h3#1251 - `srvx` TC PR: h3js/srvx#141 Closes #18123 --- **This PR is part of a stack:** - #20358 - #19224 - #19225 👈 - #19304 --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
47d85ab to
fa580dd
Compare
…is set When `sourcemaps.disable` is `'disable-upload'`, the plugin should still inject debug IDs and keep `.map` files so users can upload them manually. Previously, both `injectDebugIds()` and `deleteArtifacts()` were incorrectly gated or ungated, causing debug IDs to be skipped and source maps to be deleted even in the manual-upload workflow. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Derive `SentryNitroOptions` from `BuildTimeOptionsBase` (from `@sentry/core`) instead of picking from the bundler plugin's internal `Options` type. This provides a stable public API that follows this repo's semver, rather than exposing bundler-plugin-specific fields like `_metaOptions` and top-level `disable`. Key changes: - `url` option renamed to `sentryUrl` (consistent with other SDKs) - Top-level `disable` removed (use `sourcemaps.disable` instead) - `_metaOptions` no longer user-configurable Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ing `true` Previously, `configureSourcemapSettings` unconditionally set `config.sourcemap = true`, overriding the user's explicit `false`. This could expose source maps publicly when users intentionally disabled them. Now follows the same 3-case pattern as other meta-framework SDKs (Nuxt): 1. User disabled (false) → keep their setting, warn about unminified errors 2. User enabled (true) → keep their setting 3. User didn't set (undefined) → enable for Sentry Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
`configureSourcemapSettings` runs at build time, but the `debug` logger from `@sentry/core` is only initialized by `Sentry.init()` at runtime. Switch to `console.warn`/`console.log` so build-time warnings (e.g. source maps explicitly disabled) are actually visible to developers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The `rewriteSources` option was hardcoded to `normalizePath`, silently discarding any custom function provided by the user. Now falls back to `normalizePath` only when the user doesn't provide their own function, matching the behavior of other meta-framework SDKs (Nuxt, Next.js). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Previously `filesToDeleteAfterUpload` defaulted to `['**/*.map']` unconditionally, deleting user-generated source maps even when the user explicitly set `sourcemap: true` in their Nitro config. Now the default only applies when Sentry was the one to enable sourcemap generation. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Nitro spawns a nested Nitro instance for prerendering with the user's `modules` array re-installed, which caused the Sentry module to run twice and upload source maps + create a release twice per build. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ff591f3 to
14b31ea
Compare
| // We don't prepare the artifacts because we injected debug IDs manually before | ||
| prepareArtifacts: false, | ||
| }); | ||
| await sentryBuildPluginManager.deleteArtifacts(); |
There was a problem hiding this comment.
Did you manually also check if this deletes the correct source maps - based on the user-set source map setting?
There was a problem hiding this comment.
I tried 3 scenarios locally:
- default: Sourcemaps files get deleted
- explicit
true, sourcemap files is retained disable-upload: retained but not uploaded
I did miss that it should only delete nitro's sourcemaps (fixed now in 1c13825) but not sure what other scenarios to take into account. Also checked that it respects the filesToDeleteAfterUpload option, is that what you meant?
`filesToDeleteAfterUpload` previously defaulted to `['**/*.map']`, which is resolved from the project root and could traverse `node_modules`. Scope the default to `nitro.options.output.serverDir` so we only touch maps we generated. Also log the chosen glob in debug mode to match the Nuxt SDK UX. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
| } else { | ||
| // User did not explicitly set sourcemap — enable it for Sentry | ||
| config.sourcemap = true; | ||
| sentryEnabledSourcemaps = true; | ||
| if (moduleOptions?.debug) { |
There was a problem hiding this comment.
Bug: The function only checks for boolean config.sourcemap values, incorrectly handling valid string options like "inline" by falling into the default case and overwriting the user's setting.
Severity: MEDIUM
Suggested Fix
Update the conditional logic to correctly handle string values for config.sourcemap. Instead of strict boolean checks, use a condition that includes valid string options, such as ['hidden', true].includes(config.sourcemap), to determine if sourcemaps are enabled. This will prevent the else block from incorrectly overwriting the user's configuration.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/nitro/src/sourceMaps.ts#L158-L162
Potential issue: The `configureSourcemapSettings` function checks for `config.sourcemap`
using strict boolean comparisons (`=== true` and `=== false`). When a user provides a
valid string value like `"inline"` or `"hidden"`, these checks fail. The code then
executes the `else` block, which is intended for when the option is unset. This block
incorrectly overwrites the user's setting with `config.sourcemap = true` and enables
`sentryEnabledSourcemaps`. As a result, the user's intended sourcemap configuration is
ignored, and the generated sourcemaps are incorrectly marked for deletion after upload.

Adds automatic sourcemap handling to the Nitro SDK, using
@sentry/bundler-plugin-corefor builder-agnostic post-build upload.Nitro uses rollup or rolldown, so it made sense to make it as agnostic as possible.
Closes #17992
This PR is part of a stack: